<template>
  <div class="m-container">
    <Header></Header>

    <el-container>
      <el-aside width="200px">
        <el-row class="tac">
          <el-col :span="12">
            <h5>未完成</h5>
            <el-menu default-active="2" class="el-menu-vertical-demo" @open="handleOpen" @close="handleClose">
              <el-submenu index="1">
                <template slot="title">
                  <i class="el-icon-location"></i>
                  <span>导航</span>
                </template>
                <el-menu-item-group>
                  <template slot="title">分组一</template>
                  <el-menu-item index="1-1">选项1</el-menu-item>
                  <el-menu-item index="1-2">选项2</el-menu-item>
                </el-menu-item-group>
                <el-menu-item-group title="分组2">
                  <el-menu-item index="1-3">选项3</el-menu-item>
                </el-menu-item-group>
                <el-submenu index="1-4">
                  <template slot="title">选项4</template>
                  <el-menu-item index="1-4-1">选项1</el-menu-item>
                </el-submenu>
              </el-submenu>
              <el-menu-item index="2">
                <i class="el-icon-menu"></i>
                <span slot="title">分类</span>
              </el-menu-item>
              <el-menu-item index="3" disabled>
                <i class="el-icon-setting"></i>
                <span slot="title">设置</span>
              </el-menu-item>
              <el-menu-item index="4">
                <i class="el-icon-document"></i>
                <span slot="title" @click="toabout">关于</span>
              </el-menu-item>
            </el-menu>
          </el-col>
        </el-row>
      </el-aside>

      <el-main class="ccc">
        <el-timeline>
          <el-timeline-item v-bind:timestamp="blog.created" placement="top" v-for="blog in blogs">
            <el-card>
              <h4>
                <router-link :to="{ name: 'BlogDetail', params: { blogId: blog.id } }">{{ blog.title }}</router-link>
              </h4>
              <p>{{ blog.description }}</p>
            </el-card>
          </el-timeline-item>
        </el-timeline>

        <el-pagination class="mpage" background layout="prev, pager, next" :current-page=currentPage :page-size=pageSize
          @current-change=page :total="total">
        </el-pagination>
      </el-main>
    </el-container>
    <div class="block">
    </div>

  </div>
</template>
<script>
import Header from "@/components/Header";
export default {
  name: "Blogs",
  components: { Header },
  data() {
    return {
      blogs: {},
      currentPage: 1,
      total: 0,
      pageSize: 5
    }
  },
  methods: {
    toabout() {
      this.$router.push("/about")
    },
    handleOpen(key, keyPath) {
      console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath);
    },
    page(currentPage) {
      const _this = this
      this.$axios.get('http://localhost:8081/blogs?currentPage=' + currentPage).then((res) => {
        console.log(res.data.data.records)
        _this.blogs = res.data.data.records
        _this.currentPage = res.data.data.current
        _this.total = res.data.data.total
        _this.pageSize = res.data.data.size
      })
    }
  },
  mounted() {
    this.page(1);
  }
}
</script>

<style scoped>
div {
  animation: fadeInAnimation ease 0.5s;
  animation-iteration-count: 1;
  animation-fill-mode: forwards;
}

@keyframes fadeInAnimation {
  0% {
    opacity: 0;
  }

  100% {
    opacity: 1;
  }
}


.ccc {
  margin: 0 auto;
}

.block {
  margin: 20px;
}

.mpage {
  text-align: center;
}
</style>